package ldh.serialize.type;

import java.io.IOException;

import ldh.serialize.BinarySerialized;
import ldh.serialize.io.ByteBuf;
import ldh.serialize.util.SerializedUtil;

public class FloatSerialized implements BinarySerialized<Float> {

	@Override
	public void write(ByteBuf out, Float f) throws IOException {
		Integer data = null;
		if (f != null) {
			data =  Float.floatToIntBits(f);
		}
		SerializedUtil.writeInteger(out, data);
	}

	@Override
	public Float read(ByteBuf in) throws IOException {
		Integer data = SerializedUtil.readInteger(in);
		if (data == null) {
			return null;
		}
		return Float.intBitsToFloat(data);
	}

	@Override
	public Class<Float> getClassType() {
		return Float.class;
	}

}
